package com.dhecp.project.finance.service.impl;

import com.dhecp.core.constant.DataFiltering;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.finance.domain.FinancesEventGroups;
import com.dhecp.project.finance.mapper.FinancesEventGroupsMapper;
import com.dhecp.project.finance.service.FinancesEventGroupsService;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class FinancesEventGroupsServiceImpl extends BaseModuleServiceImpl implements FinancesEventGroupsService {

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

    @Autowired
    private FinancesEventGroupsMapper businessMapper;

    /**
     * 查询
     * @param params
     * @throws Exception
     * @author fxz
     */
    @Override
    public List<FinancesEventGroups> queryAllList(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
//        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        if (params.get("field") == null || params.get("field") == ""){
            String orderBy = "t1.createTime asc";
            PageUtils.startPageOrder(orderBy);
        }else{
            PageUtils.startPage();
        }
        if(params.get("endDateSel") != null && !params.get("endDateSel").equals("")){
            //获取店铺入账创建时间当前月份以及上一个月
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = dateFormat.parse(String.valueOf(params.get("endDateSel")));
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int month = calendar.get(Calendar.MONTH) + 1;
            calendar.add(Calendar.MONTH, -1);
            int lastMonth = calendar.get(Calendar.MONTH) + 1;
            params.put("lastMonth",lastMonth);
            params.put("month",month);
        }
        params.put("aStatusSel"," AND t1.AStatus != '匹配成功'");
        return businessMapper.select(params);
    }
}
